<!DOCTYPE html>
<html lang="zh-hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/wow/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/wow/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/wow/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/wow/images/logo.svg" color="#222">

<link rel="stylesheet" href="/wow/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"single-flower.gitee.io","root":"/wow/","images":"/wow/images","scheme":"Muse","version":"8.3.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"بحث...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
  </script>
<meta name="description" content="python内置的高阶方法lambda表达式以及跳转表不定长参数如何使用passglobal和nonlocal的作用python内置的高阶方法：   map() 1234567def add(x):    return x+xprint(map(add,[1,2,3]))&#x2F;&#x2F;Out:&lt;map object at 0x00000239E833DE48&gt;print(list(map(add">
<meta property="og:type" content="article">
<meta property="og:title" content="函数基础6">
<meta property="og:url" content="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E5%9F%BA%E7%A1%806/index.html">
<meta property="og:site_name" content="朵朵最可爱">
<meta property="og:description" content="python内置的高阶方法lambda表达式以及跳转表不定长参数如何使用passglobal和nonlocal的作用python内置的高阶方法：   map() 1234567def add(x):    return x+xprint(map(add,[1,2,3]))&#x2F;&#x2F;Out:&lt;map object at 0x00000239E833DE48&gt;print(list(map(add">
<meta property="og:locale">
<meta property="article:published_time" content="2021-04-13T10:39:12.057Z">
<meta property="article:modified_time" content="2021-04-14T23:55:39.165Z">
<meta property="article:author" content="X y">
<meta property="article:tag" content="-GIT">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E5%9F%BA%E7%A1%806/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-hans'
  };
</script>
<title>函数基础6 | 朵朵最可爱</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="تشغيل شريط التصفح" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/wow/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">朵朵最可爱</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/wow/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li>
        <li class="menu-item menu-item-about"><a href="/wow/about/" rel="section"><i class="fa fa-user fa-fw"></i>معلومات</a></li>
        <li class="menu-item menu-item-tags"><a href="/wow/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>الوسوم</a></li>
        <li class="menu-item menu-item-categories"><a href="/wow/categories/" rel="section"><i class="fa fa-th fa-fw"></i>التصنيفات</a></li>
        <li class="menu-item menu-item-archives"><a href="/wow/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>الأرشيفات</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          المحتويات
        </li>
        <li class="sidebar-nav-overview">
          عام
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#python%E5%86%85%E7%BD%AE%E7%9A%84%E9%AB%98%E9%98%B6%E6%96%B9%E6%B3%95"><span class="nav-number">1.</span> <span class="nav-text">python内置的高阶方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%A5%E5%8F%8A%E8%B7%B3%E8%BD%AC%E8%A1%A8"><span class="nav-number">2.</span> <span class="nav-text">lambda表达式以及跳转表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%8D%E5%AE%9A%E9%95%BF%E5%8F%82%E6%95%B0%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8"><span class="nav-number">3.</span> <span class="nav-text">不定长参数如何使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pass"><span class="nav-number">4.</span> <span class="nav-text">pass</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#global%E5%92%8Cnonlocal%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="nav-number">5.</span> <span class="nav-text">global和nonlocal的作用</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#python%E5%86%85%E7%BD%AE%E7%9A%84%E9%AB%98%E9%98%B6%E6%96%B9%E6%B3%95%EF%BC%9A"><span class="nav-number"></span> <span class="nav-text">python内置的高阶方法：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BB%A5%E5%8F%8A%E8%B7%B3%E8%BD%AC%E8%A1%A8-1"><span class="nav-number"></span> <span class="nav-text">lambda表达式以及跳转表:</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%8D%E5%AE%9A%E9%95%BF%E5%8F%82%E6%95%B0%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%EF%BC%9A"><span class="nav-number"></span> <span class="nav-text">不定长参数如何使用：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#pass%EF%BC%9A"><span class="nav-number"></span> <span class="nav-text">pass：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#global%E5%92%8Cnonlocal%E7%9A%84%E4%BD%9C%E7%94%A8%EF%BC%9A"><span class="nav-number"></span> <span class="nav-text">global和nonlocal的作用：</span></a></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">X y</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/wow/archives/">
        
          <span class="site-state-item-count">23</span>
          <span class="site-state-item-name">المقالات</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">التصنيفات</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">الوسوم</span>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-hans">
    <link itemprop="mainEntityOfPage" href="https://single-flower.gitee.io/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E5%87%BD%E6%95%B0%E5%9F%BA%E7%A1%806/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/wow/images/avatar.gif">
      <meta itemprop="name" content="X y">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="朵朵最可爱">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          函数基础6
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">نُشر في</span>

      <time title="أُنشأ: 2021-04-13 18:39:12" itemprop="dateCreated datePublished" datetime="2021-04-13T18:39:12+08:00">2021-04-13</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">عُدل في</span>
        <time title="عُدل: 2021-04-15 07:55:39" itemprop="dateModified" datetime="2021-04-15T07:55:39+08:00">2021-04-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">في</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/wow/categories/GIT/" itemprop="url" rel="index"><span itemprop="name">-GIT</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h3 id="python内置的高阶方法"><a href="#python内置的高阶方法" class="headerlink" title="python内置的高阶方法"></a>python内置的高阶方法</h3><h3 id="lambda表达式以及跳转表"><a href="#lambda表达式以及跳转表" class="headerlink" title="lambda表达式以及跳转表"></a>lambda表达式以及跳转表</h3><h3 id="不定长参数如何使用"><a href="#不定长参数如何使用" class="headerlink" title="不定长参数如何使用"></a>不定长参数如何使用</h3><h3 id="pass"><a href="#pass" class="headerlink" title="pass"></a>pass</h3><h3 id="global和nonlocal的作用"><a href="#global和nonlocal的作用" class="headerlink" title="global和nonlocal的作用"></a>global和nonlocal的作用</h3><h2 id="python内置的高阶方法："><a href="#python内置的高阶方法：" class="headerlink" title="python内置的高阶方法："></a>python内置的高阶方法：</h2><p>   map()</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">def add(x):</span><br><span class="line">    <span class="keyword">return</span> x+x</span><br><span class="line"></span><br><span class="line">print(map(add,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]))</span><br><span class="line"><span class="comment">//Out:&lt;map object at 0x00000239E833DE48&gt;</span></span><br><span class="line">print(list(map(add,[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])))</span><br><span class="line"><span class="comment">//Out:[2,4,6]</span></span><br></pre></td></tr></table></figure>

<h2 id="lambda表达式以及跳转表-1"><a href="#lambda表达式以及跳转表-1" class="headerlink" title="lambda表达式以及跳转表:"></a>lambda表达式以及跳转表:</h2><pre><code>--lambda</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">add = lambda x, <span class="attr">y</span> : x+y</span><br><span class="line"></span><br><span class="line">add(<span class="number">1</span>,<span class="number">2</span>) <span class="comment">//结果为3</span></span><br></pre></td></tr></table></figure>
<pre><code>--跳跃表是为了解决平衡树插入或者删除操作过于复杂而进行设计的
跳跃表有如下特点：

(1) 每个跳跃表由很多层结构组成；
(2) 每一层都是一个有序链表，且第一个节点是头节点；
(3) 最底层的有序链表包含所有节点；
(4) 每个节点可能有多个指针，这与节点所包含的层数有关；
(5) 跳跃表的查找、插入、删除的时间复杂度均为O(log N)。</code></pre>
<h2 id="不定长参数如何使用："><a href="#不定长参数如何使用：" class="headerlink" title="不定长参数如何使用："></a>不定长参数如何使用：</h2><pre><code>--*args接收单个出现的参数，接收后存为元组
--**kwargs接收以键值对形式出现的参数，接收后存为一个字典</code></pre>
<h2 id="pass："><a href="#pass：" class="headerlink" title="pass："></a>pass：</h2><pre><code>--空语句  占位的作用</code></pre>
<h2 id="global和nonlocal的作用："><a href="#global和nonlocal的作用：" class="headerlink" title="global和nonlocal的作用："></a>global和nonlocal的作用：</h2><pre><code>--global是全局变量，用在任何地方</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//如果未使用 </span></span><br><span class="line">x = <span class="number">1</span></span><br><span class="line"> </span><br><span class="line">def func():k<span class="string">&#x27;b&#x27;</span>h</span><br><span class="line">    x = <span class="number">2</span></span><br><span class="line"> </span><br><span class="line">func()</span><br><span class="line">print(x)       <span class="comment">//1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//使用了</span></span><br><span class="line">x = <span class="number">1</span>      </span><br><span class="line"> </span><br><span class="line">def func():</span><br><span class="line">    <span class="built_in">global</span> x</span><br><span class="line">    x = <span class="number">2</span></span><br><span class="line"> </span><br><span class="line">func()</span><br><span class="line">print(x)      <span class="comment">//2</span></span><br></pre></td></tr></table></figure>
<pre><code>nonlocal是上一级函数中的局部变量，只能用在嵌套函数中</code></pre>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">def b():</span><br><span class="line">  num2=<span class="number">1</span></span><br><span class="line">  def c():</span><br><span class="line">   nonlocal num2    <span class="comment">//为了修改非全局变量</span></span><br><span class="line">   num2+=<span class="number">2</span></span><br><span class="line">   print(num2)</span><br><span class="line">  <span class="keyword">return</span> c</span><br><span class="line">b()()</span><br></pre></td></tr></table></figure>






    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/wow/tags/GIT/" rel="tag"># -GIT</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A19/" rel="prev" title="面向对象9">
                  <i class="fa fa-chevron-left"></i> 面向对象9
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/wow/2021/04/13/SD/%E9%9D%A2%E8%AF%95%E9%A2%98_%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B3/" rel="next" title="数据类型3">
                  数据类型3 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">X y</span>
</div>
  <div class="powered-by">تطبيق الموقع <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/wow/js/utils.js"></script><script src="/wow/js/motion.js"></script><script src="/wow/js/schemes/muse.js"></script><script src="/wow/js/next-boot.js"></script>

  






  





</body>
</html>
